package com.hzzc.core.controller.back;

import com.hzzc.Result;
import com.hzzc.core.service.RoleResourceRelationService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
 * @author zmm
 * 用户角色服务
 */
@RestController
@RequestMapping("/back")
public class BackRoleResourceController {

    @Autowired
    private RoleResourceRelationService roleResourceRelationService;

    @GetMapping("/roleResources")
    public Result<Set<Long>> roleResources(@RequestParam("appId") Long appId, @RequestParam("roleId") Long roleId) {
        return Result.success(roleResourceRelationService.getRoleResourceIds(appId, roleId), "");
    }

    @PostMapping("/roleResource")
    public Result<Set<Long>> updateRoleResources(@RequestBody RoleResourcesBean roleResourcesBean) {
        roleResourceRelationService.updateRoleResources(roleResourcesBean.appId, roleResourcesBean.roleId, roleResourcesBean.resourceIds);
        return Result.success(roleResourceRelationService.getRoleResourceIds(roleResourcesBean.appId, roleResourcesBean.roleId), "");
    }


    @Data
    static class RoleResourcesBean {

        private long appId;

        private Set<Long> resourceIds;

        private long roleId;

    }


}
